package cn.rkylin.oms.system.messageDefine.service;

import java.util.Arrays;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageInfo;

import cn.rkylin.core.service.ApolloService;
import cn.rkylin.oms.system.appClient.vo.AppClientVo;
import cn.rkylin.oms.system.messageDefine.dao.IMessageDefineDao;
import cn.rkylin.oms.system.messageDefine.domain.OMS_MESSAGE;
import cn.rkylin.oms.system.messageDefine.domain.OMS_MESSAGE_SHOP;
import cn.rkylin.oms.system.messageDefine.vo.MessageDefineVo;
import cn.rkylin.oms.system.messageDefine.vo.MessageShopVo;
import cn.rkylin.oms.system.shop.dao.IShopDAO;

@Service("messageDefineService")
public class MessageDefineServiceImpl extends ApolloService implements IMessageDefineService{
	@Autowired
	private IMessageDefineDao messageDefineDao;
	@Autowired
	private IShopDAO shopDAO;
	/**
	 * 方法简要描述信息.
	 * <p>
	 * 描述: 根据条件获取物流公司
	 * </p>
	 * <p>
	 * 备注: 详见顺序图
	 * </p>
	 *
	 */
	public PageInfo<MessageDefineVo> findByWhere(int page, int rows, MessageDefineVo messVo) throws Exception {
		PageInfo<MessageDefineVo> messVOList = findPage(page, rows, "getMessageList", messVo);
		return messVOList;
	}
//	@Override
//	public void saveMessage(OMS_MESSAGE message) throws Exception {
//		message.setMsgId(UUID.randomUUID().toString().replaceAll("-", ""));
//		message.setDeleted("n");
//		messageDefineDao.saveMessage(message);
//		
//	}
	@Override
	public void delete(String msgId) throws Exception {
		messageDefineDao.delete("deleteMsg", msgId);
	}
	@Override
	public void deleteShopMes(String msgId) throws Exception {
		
		List<String> listid = Arrays.asList(msgId.split(","));
		for (int i = 0; i < listid.size(); i++) {
			messageDefineDao.deleteShopMes("deleteShopMes", listid.get(i));
		}
		
	}
	@Override
	public void doEnable(String msgEnable,String msgId) throws Exception {
		messageDefineDao.doEnable(msgEnable,msgId);
	}
	@Override
	public OMS_MESSAGE getMessageInfo(OMS_MESSAGE message) throws Exception {
		return messageDefineDao.getMessageInfo(message);
	}
	public void takeSaveShop(String[] arr,String msgId,String template) throws Exception {
		for(String s:arr){
			OMS_MESSAGE_SHOP ms=new OMS_MESSAGE_SHOP();
			ms.setMsgId(msgId);
			ms.setShopId(s);
			ms.setMsId(UUID.randomUUID().toString().replaceAll("-", ""));
			ms.setTemplate(template);
			messageDefineDao.insertMessageShop(ms);
		}
	}
	@Override
	public List getMsgByCondition(MessageDefineVo messageDefineVoVO) throws Exception {
		try {
			return messageDefineDao.getMsgByCondition(messageDefineVoVO);
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception();
		}
	}
	@Override
	public void insert(MessageDefineVo messageDefineVoVO) throws Exception {
		messageDefineDao.insert(messageDefineVoVO);
	}
	@Override
	public PageInfo<MessageShopVo> findShopByWhere(int page, int length, MessageShopVo param) throws Exception {
		return findPage(page, length, "getShopMsgList", param);
	}
	@Override
	public OMS_MESSAGE_SHOP getMessageShop(OMS_MESSAGE_SHOP messageShop) throws Exception {
		return messageDefineDao.getMessageShop(messageShop);
	}
	@Override
	public void updateFormFree(OMS_MESSAGE_SHOP messageShop) throws Exception {
		messageDefineDao.updateFormFree(messageShop);
	}
	@Override
	public void updateMessage(MessageDefineVo msgVO) throws Exception {
		messageDefineDao.updateMessage(msgVO);
		
	}
}
